/*
 * Copyright (C) 2010 TopCoder Inc., All Rights Reserved.
 */
package com.hercules.android.receiver.entities;

import org.json.JSONObject;

import android.graphics.Bitmap;

import com.hercules.android.receiver.XREObjectFormatterException;

/**
 * <p>
 * A POJO contains the data of XREImage resource.
 * </p>
 * 
 * @author TCSASSEMBER
 * @version 1.0
 */
public class XREImage extends XREObject {
    /**
     * Represents the URL to the image file.
     */
    private String url;

    /**
     * Represents the image quality.
     */
    private String quality;

    /**
     * Represents the <code>Bitmap</code> of this image.
     */
    Bitmap bitmap;

    /**
     * Default constructor. Set the default values.
     */
    public XREImage() {
        super();
    }

    /**
     * Gets the URL to the image file.
     * 
     * @return the URL to the image file
     */
    public String getUrl() {
        return url;
    }

    /**
     * Sets the URL to the image file.
     * 
     * @param url
     *            the URL to the image file
     */
    public void setUrl(String url) {
        this.url = url;
    }

    /**
     * Gets the image quality.
     * 
     * @return the image quality
     */
    public String getQuality() {
        return quality;
    }

    /**
     * Sets the image quality.
     * 
     * @param quality
     *            the image quality
     */
    public void setQuality(String quality) {
        this.quality = quality;
    }

    /**
     * Gets the <code>Bitmap</code> of this image.
     * 
     * @return the <code>Bitmap</code> of this image
     */
    public Bitmap getBitmap() {
        return bitmap;
    }

    /**
     * Sets the <code>Bitmap</code> of this image.
     * 
     * @param bitmap
     *            the <code>Bitmap</code> of this image
     */
    public void setBitmap(Bitmap bitmap) {
        this.bitmap = bitmap;
    }

    /**
     * Set properties from <code>JSONObject</code>.
     * 
     * @param json
     *            the <code>JSONObject</code> instance
     * @throws XREObjectFormatterException
     *             if any error occurs
     */
    public void setProperties(JSONObject json) throws XREObjectFormatterException {
        String oriUrl = url;
        super.setProperties(json);
        if (oriUrl != null && !oriUrl.equals(url)) {
            bitmap = null;
        }
    }
}
